package com.dxf.sysadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dxf.common.utils.ResultJson;
import com.dxf.sysadmin.entity.Clazz;
import com.dxf.sysadmin.entity.EvaluteTask;
import com.dxf.sysadmin.entity.qo.MyPage;
import com.dxf.sysadmin.mapper.EvaluteTaskMapper;
import com.dxf.sysadmin.service.EvaluteTaskService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 评价任务表 服务实现类
 */
@Service
public class EvaluteTaskServiceImpl extends ServiceImpl<EvaluteTaskMapper, EvaluteTask> implements EvaluteTaskService {

    /**
     *评教任务列表查询
     */
    @Override
    public ResultJson taskPage(MyPage qry) {
        Page<EvaluteTask> page = new Page<>(qry.getPage(), qry.getLimit());

        IPage<EvaluteTask> iPage = page(page);
        Map<String, Object> map = new HashMap<>();
        map.put("rows",iPage.getRecords());
        map.put("total",iPage.getTotal());
        return ResultJson.ok().data(map);
    }

    /**
     *更具id列表删除评教任务
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson deleteTask(List<Long> list) {
        removeByIds(list);
        //TODO
        return ResultJson.ok();
    }

    /**
     *新增或者更新评教任务
     */
    @Transactional(rollbackFor = Exception.class)
    @Override
    public ResultJson saveOrUpdateTask(EvaluteTask target) {
        saveOrUpdate(target);
        return ResultJson.ok();
    }

    /**
     *获取评教任务列表
     */
    @Override
    public ResultJson listTask() {
        Date now  = new Date();
        return ResultJson.ok().data("listTask",list(new QueryWrapper<EvaluteTask>().
                lambda().le(EvaluteTask::getStartDate,now).
                ge(EvaluteTask::getEndDate,now).eq(EvaluteTask::getStatus,0)));
    }
}
